<template>
  <div class="bottom-bar">
    <div class="left">
      <div class="item" @click="showShare = true">
        <image src="/static/images/share.png" />
        <div>分享</div>
      </div>
      <div class="item" @click="collect()">
        <image v-if="hotel.isCollection" src="/static/images/ysc.png" />
        <image v-else src="/static/images/sc.png" />
        <div>收藏</div>
      </div>
    </div>
    <div class="price">{{ hotel.price }}</div>
    <div class="btn active" @click="placeOrde(hotel)">立即预定</div>
  </div>

  <ShareMode v-model="showShare" isCustomNav />
</template>
<script setup lang="ts">
import { msgSuccess, showModal } from '@/utils/index'
defineOptions({ name: 'BottomBar' })

const props = defineProps(['hotel'])
const emits = defineEmits(['placeOrde', 'getData'])

const showShare = ref(false)

async function collect() {
  if (props.hotel.isCollection) {
    const res = await showModal({
      title: '提示',
      content: '是否取消收藏',
    })

    if (!res) {
      return
    }
  }
  uni.showLoading()
  http
    .post('/hotels-layout-app/collection', {
      layoutId: props.hotel.id,
    })
    .then(() => {
      msgSuccess('操作成功').then(() => {
        emits('getData')
      })
    })
    .finally(() => {
      uni.hideLoading()
    })
}

function placeOrde(hotel) {
  emits('placeOrde', hotel)
}
</script>
<style lang="scss" scoped>
.bottom-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 128rpx;
  padding: 0px 30rpx;
  padding-bottom: calc(constant(safe-area-inset-bottom)) !important;
  padding-bottom: calc(env(safe-area-inset-bottom)) !important;
  background: #ffffff;
  box-shadow: 0px -7rpx 23rpx rgba(#a6a6a6, 0.1);

  .left {
    display: flex;
    .item {
      margin-right: 56rpx;
      font-size: 23rpx;
      color: var(--color1);
      text-align: center;
      image {
        width: 35rpx;
        height: 35rpx;
        margin-bottom: 6rpx;
      }
    }
  }
  .price {
    font-size: 39rpx;
    font-weight: 700;
    color: var(--color1);
    &::before {
      font-size: 23rpx;
      content: '￥';
    }
    &::after {
      font-size: 23rpx;
      font-weight: 600;
      content: '/晚';
    }
  }
  .btn {
    width: 200rpx;
    height: 70rpx;
    font-size: 30rpx;
    font-weight: 600;
    line-height: 66rpx;
    color: #fff;
    text-align: center;
    background: #1f2026;
    border-radius: 35rpx;
    box-shadow: 0px 17rpx 29rpx rgba(#1f2026, 0.3);
  }
}
</style>
